<template>
  <div class="withdraw-audit" v-loading="operateloading">
    <!-- 搜索栏 -->
    <div class="search-block">
      <div class="left-group">
        <div class="item-msg">
          <label>币种</label>
          <el-select v-model="searchForm.currency" placeholder size="small" style="width:100px">
            <el-option
              v-for="item in currencyList"
              :key="item.coin_id"
              :label="item.currency"
              :value="item.currency"
            ></el-option>
          </el-select>
        </div>
        <div class="item-msg">
          <el-input
            v-model="searchForm.search"
            clearable
            size="small"
            placeholder="uid/手机/邮箱/地址"
            style="width: 200px;"
          ></el-input>
        </div>
        <div class="item-msg">
          <label>状态</label>
          <el-select v-model="searchForm.withdraw_review_status" placeholder size="small">
            <el-option
              v-for="item in status"
              :label="item.label"
              :value="item.value"
              :key="item.value"
            ></el-option>
          </el-select>
        </div>
        <br>
        <div class="item-msg">
          <label>时间</label>
          <el-date-picker
            size="medium"
            v-model="searchForm.times"
            type="daterange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </div>
        <el-button class="search-btn" @click="search()" size="medium" type="primary">查询</el-button>
        <el-button class="search-btn" @click="reset()" size="medium">重置</el-button>
        <el-button class="search-btn" size="medium" @click="showDialog = true">导出</el-button>
      </div>
    </div>
    <!-- 数据表 -->
    <div class="data-table">
      <el-table
        v-loading="loading"
        element-loading-text="拼命加载中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(211, 215, 212, 0.5)"
        :data="tableData"
        stripe
        header-cell-class-name="headerStyle"
        style="width: 100%"
      >
        <el-table-column align="center" prop="uid" label="uid" width="80"></el-table-column>
        <el-table-column align="center" prop="username" label="姓名"></el-table-column>
        <el-table-column align="center" prop="mobile" label="手机号"></el-table-column>
        <el-table-column align="center" prop="email" label="邮箱"></el-table-column>
        <el-table-column align="center" prop="currency" label="币种"></el-table-column>
        <el-table-column align="center" prop="amount" label="数量"></el-table-column>
        <el-table-column align="center" prop="op_address" width="165" label="对方地址"></el-table-column>
        <el-table-column align="center" prop="created_at" width="165" label="提交时间"></el-table-column>
        <el-table-column align="center" prop="status_msg" label="状态"></el-table-column>
        <el-table-column align="center" label="类型">
          <template slot-scope="item">{{item.row.op_address_source|type}}</template>
        </el-table-column>
        <el-table-column align="center" prop="inviter" label="操作" width="150">
          <template slot-scope="item">
            <el-button
              type="text"
              @click="operate(item.row,'1')"
              class="edit-btn"
              v-if="item.row.status === 0"
            >通过</el-button>
            <el-button
              type="text"
              @click="operate(item.row,'2')"
              class="cancel-btn"
              v-if="item.row.status === 0"
            >拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pages
        :pages="searchForm"
        :total="total"
        @pageSizeChange="pageSizeChange"
        @pageChange="pageChange"
      ></pages>
    </div>
    <!-- 导出excel -->
    <transition name="fade">
      <excelDialog
        v-if="showDialog"
        @cancel="showDialog=false"
        @success="showDialog=false"
        :fnc="back"
        :params="searchForm"
      ></excelDialog>
    </transition>
  </div>
</template>

<script>
import Pages from "@/components/PageBox.vue";
import excelDialog from "@/components/AssetsManage/excelDialog";
import { GetWithdrawAudit, UpdateWithdrawAudit } from "./Assets.service";
import { supTokens } from "../FlashChange/FlashChange.service";

export default {
  components: {
    Pages,
    excelDialog
  },
  data() {
    return {
      operateloading: false,
      loading: false,
      searchForm: {
        currency: "",
        search: "",
        withdraw_review_status: "",
        page: 1,
        size: 10,
        start_time: null,
        end_time: null,
        times: []
      },
      currencyList: [],
      tableData: [],
      total: 10,
      showDialog: false
    };
  },
  filters: {
    type(val) {
      return val == 0 ? "待确认" : val == 1 ? "内部" : "外部";
    }
  },
  mounted() {
    this.init();
  },
  computed: {
    status() {
      return [
        { label: "待审核", value: "1" },
        { label: "已通过", value: "2" },
        { label: "未通过", value: "3" }
      ];
    }
  },
  methods: {
    async init() {
      this.search();
      let res2 = await supTokens();
      this.currencyList = res2.data || [];
    },
    async search() {
      this.loading = true;
      if (this.searchForm.times && this.searchForm.times.length > 0) {
        this.searchForm.start_time = this.searchForm.times[0];
        this.searchForm.end_time = this.searchForm.times[1];
      } else {
        this.searchForm.start_time = this.searchForm.end_time = null;
      }
      const res = await GetWithdrawAudit(this.searchForm);
      this.tableData = res.data ? res.data.data : [];
      this.total = res.data ? Number(res.data.count) : 0;
      this.loading = false;
    },
    async operate(row, op) {
      let param = {
        id: row.id,
        withdraw_review_op: op
      };
      this.operateloading = true;
      const res = await UpdateWithdrawAudit(param);
      this.operateloading = false;
      if (res.code == 1) {
        this.$notify.success({
          title: "提示",
          message: "操作成功"
        });
        this.search();
      }
    },
    reset() {
      this.searchForm = {
        currency: "",
        search: "",
        withdraw_review_status: "",
        page: 1,
        size: 10,
        start_time: null,
        end_time: null,
        times: []
      };
    },
    back(params) {
      return GetWithdrawAudit(params);
    },
    pageChange(val) {
      this.searchForm.page = val;
      this.search(val);
    },
    pageSizeChange(val) {
      this.searchForm.size = val;
      this.searchForm.page = 1;
      this.search();
    }
  }
};
</script>

<style lang="scss" scoped>
.withdraw-audit {
  .search-block {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 25px 30px;
    border-radius: 5px;
    background: #fff;
    box-shadow: rgba(0, 0, 0, 0.1) 0 0 15px;

    .item-msg {
      display: inline-block;
      margin-right: 20px;
      height: 60px;
      line-height: 60px;
      font-size: 1 size= "medium" 4;
      color: $admin_font_param;

      label {
        display: inline-block;
        min-width: 50px;
        text-align: right;
        margin-right: 10px;
      }

      .el-input {
        width: 150px;
      }

      .el-select {
        width: 150px;
      }

      .el-date-editor {
        width: 270px;
      }
    }

    .search-btn {
      margin-left: 30px;
    }

    .search-btn:nth-of-type(1) {
      margin-left: 50px;
    }

    .left-group {
    }

    .right-group {
      display: flex;

      span {
        margin-right: 10px;
      }
    }
  }

  .data-table {
    padding-bottom: 20px;
    background: #fff;
    border-radius: 5px;
    margin-top: 30px;
    box-shadow: rgba(0, 0, 0, 0.1) 0 0 15px;
  }

  .cancel-btn {
    color: red;
  }
}
</style>
